unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, XPMan, ExtCtrls, Buttons;

type
  TForm1 = class(TForm)
    edt1: TEdit;
    edt3: TEdit;
    edt2: TEdit;
    edt4: TEdit;
    edt5: TEdit;
    edt6: TEdit;
    edt9: TEdit;
    edt8: TEdit;
    edt7: TEdit;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Edit3: TEdit;
    Edit4: TEdit;
    Panel2: TPanel;
    Panel3: TPanel;
    Button1: TButton;


    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);

    procedure edt2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);

    procedure edt3KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt4KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt5KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt6KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt7KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt8KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt9KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Button1Click(Sender: TObject);

  private
    { Private declarations }
    x : integer;
    y : integer;
  public
    { Public declarations }
    procedure GameX;
    procedure GameY;
    procedure Limpar;
    procedure Zerar;
  end;

var
  Form1: TForm1;

implementation



uses Unit2;{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
begin
  edt1.Text := '';
  edt2.Text := '';
  edt3.Text := '';
  edt4.Text := '';
  edt5.Text := '';
  edt6.Text := '';
  edt7.Text := '';
  edt8.Text := '';
  edt9.Text := '';
end;

procedure TForm1.edt1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   GameX;
   GameY;
end;

procedure TForm1.edt2KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
   GameY;
end;

procedure TForm1.edt3KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   GameX;
   GameY;
end;

procedure TForm1.edt4KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
  GameY;
end;

procedure TForm1.edt5KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
  GameY;
end;

procedure TForm1.edt6KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
  GameY;
end;

procedure TForm1.edt7KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
   GameY;
end;

procedure TForm1.edt8KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
   GameY;
end;

procedure TForm1.edt9KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  GameX;
   GameY;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Form2.Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x := 0;
  y := 0;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Visible:= false;
end;

procedure TForm1.GameX;
begin
   if edt1.Text = 'x' then
   if edt2.Text = 'x' then
   if edt3.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt1.Text = 'x' then
   if edt5.Text = 'x' then
   if edt9.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;


   if edt3.Text = 'x' then
   if edt5.Text = 'x' then
   if edt7.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt1.Text = 'x' then
   if edt4.Text = 'x' then
   if edt7.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt2.Text = 'x' then
   if edt5.Text = 'x' then
   if edt8.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt3.Text = 'x' then
   if edt6.Text = 'x' then
   if edt9.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt4.Text = 'x' then
   if edt5.Text = 'x' then
   if edt6.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;

   if edt7.Text = 'x' then
   if edt8.Text = 'x' then
   if edt9.Text = 'x' then
   begin
    ShowMessage('O jogador(a) '+ Edit1.Text + ' venceu');
    Inc(x);
    Edit3.Text := IntToStr(x);
    Zerar;
   end;
end;

procedure TForm1.GameY;
begin

   if edt1.Text = 'o' then
   if edt2.Text = 'o' then
   if edt3.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt1.Text = 'o' then
   if edt5.Text = 'o' then
   if edt9.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;


   if edt3.Text = 'o' then
   if edt5.Text = 'o' then
   if edt7.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt1.Text = 'o' then
   if edt4.Text = 'o' then
   if edt7.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt2.Text = 'o' then
   if edt5.Text = 'o' then
   if edt8.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt3.Text = 'o' then
   if edt6.Text = 'o' then
   if edt9.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt4.Text = 'o' then
   if edt5.Text = 'o' then
   if edt6.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

   if edt7.Text = 'o' then
   if edt8.Text = 'o' then
   if edt9.Text = 'o' then
   begin
    ShowMessage('O jogador(a) '+ Edit2.Text + ' venceu');
    Inc(y);
    Edit4.Text := IntToStr(y);
    Zerar;
   end;

end;

procedure TForm1.Limpar;
begin
  edt1.Text := '';
  edt2.Text := '';
  edt3.Text := '';
  edt4.Text := '';
  edt5.Text := '';
  edt6.Text := '';
  edt7.Text := '';
  edt8.Text := '';
  edt9.Text := '';
  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  Edit4.Text := '';
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  Limpar;
  x := 0;
  y := 0;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Zerar;
begin
  edt1.Text := '';
  edt2.Text := '';
  edt3.Text := '';
  edt4.Text := '';
  edt5.Text := '';
  edt6.Text := '';
  edt7.Text := '';
  edt8.Text := '';
  edt9.Text := '';

end;

end.
